using System.ComponentModel;
using System;
using XmlStudio.Interfaces;

namespace XmlStudio.ViewModel.Node {
    [Serializable]
    public class XmlAttributeViewModel : INotifyPropertyChanged, IBigXmlAttribute {
        #region Fields
        string prefix;
        string localName;
        string namespaceURI;
        string value;
        #endregion

        #region Properties
        public string Prefix {
            get { return this.prefix; }
            set {
                this.prefix = value;
                OnPropertyChanged("Prefix");
            }
        }

        public string LocalName {
            get { return this.localName; }
            set {
                this.localName = value;
                OnPropertyChanged("LocalName");
            }
        }

        public string Name {
            get { return string.IsNullOrEmpty(Prefix) ? LocalName : string.Format("{0}:{1}", Prefix, LocalName); }
        }

        public string NamespaceURI {
            get { return this.namespaceURI; }
            set {
                this.namespaceURI = value;
                OnPropertyChanged("NamespaceURI");
            }
        }

        public string Value {
            get { return this.value; }
            set {
                this.value = value;
                OnPropertyChanged("Value");
            }
        }
        #endregion

        #region Events
        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #region Event handlers
        protected void OnPropertyChanged(string propertyName) {
            if(this.PropertyChanged != null) {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
